//
//  RegisterThreeCollectionViewCell.m
//  MingJiangApp
//
//  Created by wangliang on 15/3/11.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "RegisterThreeCollectionViewCell.h"
#import "BCBaseObject.h"

@interface RegisterThreeCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UITextField *secretTextFeild;
@property (weak, nonatomic) IBOutlet UITextField *resetTextFeild;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;

@end

@implementation RegisterThreeCollectionViewCell

- (void)awakeFromNib {
    // Initialization code
}
- (IBAction)next:(id)sender {
    
    if (![BCBaseObject checkInputPassword:self.secretTextFeild.text]) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"密码为6-16位"];
    }else if (![self.resetTextFeild.text isEqual:self.secretTextFeild.text]) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"两次输入密码不一致"];
    }else if (self.nameTextField.text.length == 0) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"昵称不能为空"];
    }else {
        
        NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"];
        NSDictionary *dic = @{@"user_name":name,
                              @"password":self.secretTextFeild.text,
                              @"nickname":self.nameTextField.text,
                              @"type":@"0"};
        [WLHttpRequestAfter userRegisterWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
            
            if ([resultDictionary[@"status"] integerValue] == 1) {
                
                if ([self.delegate respondsToSelector:@selector(registerViewGoToNext:withObject:)]) {
                    
                    [self.delegate registerViewGoToNext:@"设置密码" withObject:self];
                }
            }else  if ([resultDictionary[@"status"] integerValue] == 1) {
                
                [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"创建失败"];
            }
        } andFailureBlock:^(NSError *resultError) {
            
        }];
    }
    
}

- (IBAction)goBack:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(registerViewGoToBack:withObject:)]) {
        
        [self.delegate registerViewGoToBack:@"" withObject:self];
    }
}

- (IBAction)cancel:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(registerViewCancel:withObject:)]) {
        
        [self.delegate registerViewCancel:@"" withObject:self];
    }
}


@end
